// pages/order/detail/detail.js

var api = require('../../../service/api.js')
var dic = require('../../../utils/dictionary.js')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        order: {}
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var orderCode = options.orderCode || '1812131738245817';
        this.getOrder(orderCode);
    },

    getOrder(orderCode) {
        api.findOrderByOrderCode(orderCode).then(resp => {
            var order = resp.data, orderCount = 0;
            order.address = order.addressInfo.province + order.addressInfo.city + order.addressInfo.area + order.addressInfo.addressDetail;
            order.orderStatusName = dic.OrderStatus.find(order.orderStatus);
            console.log('order', order);

            order.prodList.map(prod => {
                orderCount += prod.prodCount;
                if (prod.prodImage) {
                    prod.prodImages = prod.prodImage.split(',');
                    prod.firstProdImage = prod.prodImages[0];
                }
            });
            this.setData({
                order: order
            })
        })
    },

    goodsDetail(event) {
        var goods = event.currentTarget.dataset.goods;
        wx.setStorageSync('goods', goods)
        wx.navigateTo({
            url: '/pages/goods/detail'
        });
        console.log(goods);
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

})